home *** CD-ROM | disk | FTP | other *** search
- Path: status.gen.nz!usenet
- From: dteviot@iconz.co.nz (David Teviotdale)
- Newsgroups: comp.lang.c++
- Subject: Memory leak in Borland C++ Tutorial?
- Date: 10 Mar 1996 05:42:02 GMT
- Organization: Internet Company of New Zealand
- Message-ID: <4htq3a$lon@status.gen.nz>
- NNTP-Posting-Host: dteviot.internet.co.nz
- X-Newsreader: WinVN 0.93.14
-
- I have recently purchased Borland C++ 4.51, and am working my
- way through the ObjectWindows Tutorial book. However, I am
- very puzzled, as in many places, the code shown looks like
- it will cause memory leaks. For example:
-
- on page 5 is the line:
- SetMainWindow( new TFrameWindow( 0, "Sample ObjectWindows Program" ) )
-
- on page 41 the code:
- if ( new TFileSaveDialog( this, "FileData()->Execute() == IDOK ) )
- SaveFile();
-
- And there's even worse stuff elsewhere.
-
- What is going on? Currently my theories are:
- 1) The code is correct, the memory is only allocated once, and we
- rely on Windows to cleanup the allocated memory when the program
- ends. ( This might apply to the code on page 5, but I can't see
- how it applies to the code on page 41. )
- 2) The compiler ( or run time memory manager ) is VERY sophisticated,
- and can detect that in cases like above we only want the memory
- temporarily, and will automatically free it when we are done.
- 3) The code shown has been delibertely simplified to emphasise the
- basic principles of ObjectWindows, with the fine details for
- getting it to work in non-toy programs removed.
-
-